<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />

<meta name="viewport" content="width=device-width, initial-scale=1" />



<title>Using harmony in Seurat</title>

<script>// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
  var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
  var i, h, a;
  for (i = 0; i < hs.length; i++) {
    h = hs[i];
    if (!/^h[1-6]$/i.test(h.tagName)) continue;  // it should be a header h1-h6
    a = h.attributes;
    while (a.length > 0) h.removeAttribute(a[0].name);
  }
});
</script>
<style type="text/css">detaiks.chunk-details > summary.chunk-summary {
text-align: right;
}
details.chunk-details[open] > summary.chunk-summary::after {
content: "Hide";
}
details.chunk-details[open] > summary.chunk-summary > span.chunk-summary-text {
display: none;
}
</style>

<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>



<style type="text/css">
code {
white-space: pre;
}
.sourceCode {
overflow: visible;
}
</style>
<style type="text/css" data-origin="pandoc">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } 
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } 
code span.at { color: #7d9029; } 
code span.bn { color: #40a070; } 
code span.bu { color: #008000; } 
code span.cf { color: #007020; font-weight: bold; } 
code span.ch { color: #4070a0; } 
code span.cn { color: #880000; } 
code span.co { color: #60a0b0; font-style: italic; } 
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } 
code span.do { color: #ba2121; font-style: italic; } 
code span.dt { color: #902000; } 
code span.dv { color: #40a070; } 
code span.er { color: #ff0000; font-weight: bold; } 
code span.ex { } 
code span.fl { color: #40a070; } 
code span.fu { color: #06287e; } 
code span.im { color: #008000; font-weight: bold; } 
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } 
code span.kw { color: #007020; font-weight: bold; } 
code span.op { color: #666666; } 
code span.ot { color: #007020; } 
code span.pp { color: #bc7a00; } 
code span.sc { color: #4070a0; } 
code span.ss { color: #bb6688; } 
code span.st { color: #4070a0; } 
code span.va { color: #19177c; } 
code span.vs { color: #4070a0; } 
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } 
</style>
<script>
// apply pandoc div.sourceCode style to pre.sourceCode instead
(function() {
  var sheets = document.styleSheets;
  for (var i = 0; i < sheets.length; i++) {
    if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
    try { var rules = sheets[i].cssRules; } catch (e) { continue; }
    var j = 0;
    while (j < rules.length) {
      var rule = rules[j];
      // check if there is a div.sourceCode rule
      if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") {
        j++;
        continue;
      }
      var style = rule.style.cssText;
      // check if color or background-color is set
      if (rule.style.color === '' && rule.style.backgroundColor === '') {
        j++;
        continue;
      }
      // replace div.sourceCode by a pre.sourceCode rule
      sheets[i].deleteRule(j);
      sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
    }
  }
})();
</script>




<style type="text/css">body {
background-color: #fff;
margin: 1em auto;
max-width: 700px;
overflow: visible;
padding-left: 2em;
padding-right: 2em;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 1.35;
}
#TOC {
clear: both;
margin: 0 0 10px 10px;
padding: 4px;
width: 400px;
border: 1px solid #CCCCCC;
border-radius: 5px;
background-color: #f6f6f6;
font-size: 13px;
line-height: 1.3;
}
#TOC .toctitle {
font-weight: bold;
font-size: 15px;
margin-left: 5px;
}
#TOC ul {
padding-left: 40px;
margin-left: -1.5em;
margin-top: 5px;
margin-bottom: 5px;
}
#TOC ul ul {
margin-left: -2em;
}
#TOC li {
line-height: 16px;
}
table {
margin: 1em auto;
border-width: 1px;
border-color: #DDDDDD;
border-style: outset;
border-collapse: collapse;
}
table th {
border-width: 2px;
padding: 5px;
border-style: inset;
}
table td {
border-width: 1px;
border-style: inset;
line-height: 18px;
padding: 5px 5px;
}
table, table th, table td {
border-left-style: none;
border-right-style: none;
}
table thead, table tr.even {
background-color: #f7f7f7;
}
p {
margin: 0.5em 0;
}
blockquote {
background-color: #f6f6f6;
padding: 0.25em 0.75em;
}
hr {
border-style: solid;
border: none;
border-top: 1px solid #777;
margin: 28px 0;
}
dl {
margin-left: 0;
}
dl dd {
margin-bottom: 13px;
margin-left: 13px;
}
dl dt {
font-weight: bold;
}
ul {
margin-top: 0;
}
ul li {
list-style: circle outside;
}
ul ul {
margin-bottom: 0;
}
pre, code {
background-color: #f7f7f7;
border-radius: 3px;
color: #333;
white-space: pre-wrap; 
}
pre {
border-radius: 3px;
margin: 5px 0px 10px 0px;
padding: 10px;
}
pre:not([class]) {
background-color: #f7f7f7;
}
code {
font-family: Consolas, Monaco, 'Courier New', monospace;
font-size: 85%;
}
p > code, li > code {
padding: 2px 0px;
}
div.figure {
text-align: center;
}
img {
background-color: #FFFFFF;
padding: 2px;
border: 1px solid #DDDDDD;
border-radius: 3px;
border: 1px solid #CCCCCC;
margin: 0 5px;
}
h1 {
margin-top: 0;
font-size: 35px;
line-height: 40px;
}
h2 {
border-bottom: 4px solid #f7f7f7;
padding-top: 10px;
padding-bottom: 2px;
font-size: 145%;
}
h3 {
border-bottom: 2px solid #f7f7f7;
padding-top: 10px;
font-size: 120%;
}
h4 {
border-bottom: 1px solid #f7f7f7;
margin-left: 8px;
font-size: 105%;
}
h5, h6 {
border-bottom: 1px solid #ccc;
font-size: 105%;
}
a {
color: #0033dd;
text-decoration: none;
}
a:hover {
color: #6666ff; }
a:visited {
color: #800080; }
a:visited:hover {
color: #BB00BB; }
a[href^="http:"] {
text-decoration: underline; }
a[href^="https:"] {
text-decoration: underline; }

code > span.kw { color: #555; font-weight: bold; } 
code > span.dt { color: #902000; } 
code > span.dv { color: #40a070; } 
code > span.bn { color: #d14; } 
code > span.fl { color: #d14; } 
code > span.ch { color: #d14; } 
code > span.st { color: #d14; } 
code > span.co { color: #888888; font-style: italic; } 
code > span.ot { color: #007020; } 
code > span.al { color: #ff0000; font-weight: bold; } 
code > span.fu { color: #900; font-weight: bold; } 
code > span.er { color: #a61717; background-color: #e3d2d2; } 
</style>




</head>

<body>




<h1 class="title toc-ignore">Using harmony in Seurat</h1>



<details class="chunk-details" open><summary class="chunk-summary"><span class="chunk-summary-text">Code</span></summary>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" tabindex="-1"></a><span class="fu">library</span>(harmony)</span>
<span id="cb1-2"><a href="#cb1-2" tabindex="-1"></a><span class="fu">library</span>(Seurat)</span>
<span id="cb1-3"><a href="#cb1-3" tabindex="-1"></a><span class="fu">library</span>(dplyr)</span>
<span id="cb1-4"><a href="#cb1-4" tabindex="-1"></a><span class="fu">library</span>(cowplot)</span></code></pre></div>
</details>
<div id="introduction" class="section level1">
<h1>Introduction</h1>
<p>This tutorial describes how to use harmony in Seurat v5 single-cell
analysis workflows. <code>RunHarmony()</code> is a generic function is
designed to interact with Seurat objects. This vignette will walkthrough
basic workflow of Harmony with Seurat objects. Also, it will provide
some basic downstream analyses demonstrating the properties of
harmonized cell embeddings and a brief explanation of the exposed
algorithm parameters.</p>
<p>Install Harmony from CRAN with standard commands.</p>
<details class="chunk-details" open><summary class="chunk-summary"><span class="chunk-summary-text">Code</span></summary>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" tabindex="-1"></a><span class="fu">install.packages</span>(<span class="st">&#39;harmony&#39;</span>)</span></code></pre></div>
</details>
</div>
<div id="generating-the-dataset" class="section level1">
<h1>Generating the dataset</h1>
<p>For this demo, we will be aligning two groups of PBMCs <a href="https://doi.org/10.1038/nbt.4042">Kang et al., 2017</a>. In this
experiment, PBMCs are in stimulated and control conditions. The
stimulated PBMC group was treated with interferon beta.</p>
<pre><code>

## Generate SeuratObject


```r
## Source required data
data(&quot;pbmc_stim&quot;)
pbmc &lt;- CreateSeuratObject(counts = cbind(pbmc.stim, pbmc.ctrl), project = &quot;PBMC&quot;, min.cells = 5)

## Separate conditions

pbmc@meta.data$stim &lt;- c(rep(&quot;STIM&quot;, ncol(pbmc.stim)), rep(&quot;CTRL&quot;, ncol(pbmc.ctrl)))</code></pre>
<div id="optional-download-original-data" class="section level2">
<h2>(Optional) Download original data</h2>
<p>The example above contains only two thousand cells. The full <a href="https://doi.org/10.1038/nbt.4042">Kang et al., 2017</a> dataset is
deposited in the <a href="https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE96583">GEO</a>.
This analysis uses GSM2560248 and GSM2560249 samples from <a href="https://www.ncbi.nlm.nih.gov/geo/download/?acc=GSE96583&amp;format=file">GSE96583_RAW.tar</a>
file and the <a href="https://www.ncbi.nlm.nih.gov/geo/download/?acc=GSE96583&amp;format=file&amp;file=GSE96583%5Fbatch2%2Egenes%2Etsv%2Egz">GSE96583_batch2.genes.tsv.gz</a>
gene file.</p>
<details class="chunk-details"><summary class="chunk-summary"><span class="chunk-summary-text">Code</span></summary>
<div class="sourceCode" id="cb4"><pre class="sourceCode r fold-hide"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" tabindex="-1"></a><span class="fu">library</span>(Matrix)</span>
<span id="cb4-2"><a href="#cb4-2" tabindex="-1"></a><span class="do">## Download and extract files from GEO</span></span>
<span id="cb4-3"><a href="#cb4-3" tabindex="-1"></a><span class="do">##setwd(&quot;/path/to/downloaded/files&quot;)</span></span>
<span id="cb4-4"><a href="#cb4-4" tabindex="-1"></a>genes <span class="ot">=</span>  <span class="fu">read.table</span>(<span class="st">&quot;GSE96583_batch2.genes.tsv.gz&quot;</span>, <span class="at">header =</span> <span class="cn">FALSE</span>, <span class="at">sep =</span> <span class="st">&quot;</span><span class="sc">\t</span><span class="st">&quot;</span>)</span>
<span id="cb4-5"><a href="#cb4-5" tabindex="-1"></a></span>
<span id="cb4-6"><a href="#cb4-6" tabindex="-1"></a>pbmc.ctrl.full <span class="ot">=</span> <span class="fu">as.readMM</span>(<span class="st">&quot;GSM2560248_2.1.mtx.gz&quot;</span>)</span>
<span id="cb4-7"><a href="#cb4-7" tabindex="-1"></a><span class="fu">colnames</span>(pbmc.ctrl.full) <span class="ot">=</span> <span class="fu">paste0</span>(<span class="fu">read.table</span>(<span class="st">&quot;GSM2560248_barcodes.tsv.gz&quot;</span>, <span class="at">header =</span> <span class="cn">FALSE</span>, <span class="at">sep =</span> <span class="st">&quot;</span><span class="sc">\t</span><span class="st">&quot;</span>)[,<span class="dv">1</span>], <span class="st">&quot;-1&quot;</span>)</span>
<span id="cb4-8"><a href="#cb4-8" tabindex="-1"></a><span class="fu">rownames</span>(pbmc.ctrl.full) <span class="ot">=</span> genes<span class="sc">$</span>V1</span>
<span id="cb4-9"><a href="#cb4-9" tabindex="-1"></a></span>
<span id="cb4-10"><a href="#cb4-10" tabindex="-1"></a>pbmc.stim.full <span class="ot">=</span> <span class="fu">readMM</span>(<span class="st">&quot;GSM2560249_2.2.mtx.gz&quot;</span>)</span>
<span id="cb4-11"><a href="#cb4-11" tabindex="-1"></a><span class="fu">colnames</span>(pbmc.stim.full) <span class="ot">=</span> <span class="fu">paste0</span>(<span class="fu">read.table</span>(<span class="st">&quot;GSM2560249_barcodes.tsv.gz&quot;</span>, <span class="at">header =</span> <span class="cn">FALSE</span>, <span class="at">sep =</span> <span class="st">&quot;</span><span class="sc">\t</span><span class="st">&quot;</span>)[,<span class="dv">1</span>], <span class="st">&quot;-2&quot;</span>)</span>
<span id="cb4-12"><a href="#cb4-12" tabindex="-1"></a><span class="fu">rownames</span>(pbmc.stim.full) <span class="ot">=</span> genes<span class="sc">$</span>V1</span>
<span id="cb4-13"><a href="#cb4-13" tabindex="-1"></a></span>
<span id="cb4-14"><a href="#cb4-14" tabindex="-1"></a><span class="fu">library</span>(Seurat)</span>
<span id="cb4-15"><a href="#cb4-15" tabindex="-1"></a></span>
<span id="cb4-16"><a href="#cb4-16" tabindex="-1"></a>pbmc <span class="ot">&lt;-</span> <span class="fu">CreateSeuratObject</span>(<span class="at">counts =</span> <span class="fu">cbind</span>(pbmc.stim.full, pbmc.ctrl.full), <span class="at">project =</span> <span class="st">&quot;PBMC&quot;</span>, <span class="at">min.cells =</span> <span class="dv">5</span>)</span>
<span id="cb4-17"><a href="#cb4-17" tabindex="-1"></a>pbmc<span class="sc">@</span>meta.data<span class="sc">$</span>stim <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="fu">rep</span>(<span class="st">&quot;STIM&quot;</span>, <span class="fu">ncol</span>(pbmc.stim.full)), <span class="fu">rep</span>(<span class="st">&quot;CTRL&quot;</span>, <span class="fu">ncol</span>(pbmc.ctrl.full)))</span>
<span id="cb4-18"><a href="#cb4-18" tabindex="-1"></a></span>
<span id="cb4-19"><a href="#cb4-19" tabindex="-1"></a></span>
<span id="cb4-20"><a href="#cb4-20" tabindex="-1"></a></span>
<span id="cb4-21"><a href="#cb4-21" tabindex="-1"></a></span>
<span id="cb4-22"><a href="#cb4-22" tabindex="-1"></a><span class="co"># Running Harmony</span></span>
<span id="cb4-23"><a href="#cb4-23" tabindex="-1"></a></span>
<span id="cb4-24"><a href="#cb4-24" tabindex="-1"></a>Harmony works on an existing matrix with cell embeddings and outputs its transformed version with the datasets aligned according to some user<span class="sc">-</span>defined experimental conditions. By default, harmony will look up the <span class="st">`</span><span class="at">pca</span><span class="st">`</span> cell embeddings and use these to run harmony. Therefore, it assumes that the Seurat object has these embeddings already precomputed.</span>
<span id="cb4-25"><a href="#cb4-25" tabindex="-1"></a></span>
<span id="cb4-26"><a href="#cb4-26" tabindex="-1"></a><span class="do">## Calculate PCA cell embeddings</span></span>
<span id="cb4-27"><a href="#cb4-27" tabindex="-1"></a></span>
<span id="cb4-28"><a href="#cb4-28" tabindex="-1"></a>Here, using <span class="st">`</span><span class="at">Seurat::NormalizeData()</span><span class="st">`</span>, we will be generating a union of highly variable genes using each <span class="fu">condition</span> (the control and stimulated cells). These features are going to be subsequently used to generate the <span class="dv">20</span> PCs with <span class="st">`</span><span class="at">Seurat::RunPCA()</span><span class="st">`</span>.</span></code></pre></div>
</details>
<details class="chunk-details" open><summary class="chunk-summary"><span class="chunk-summary-text">Code</span></summary>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" tabindex="-1"></a>pbmc <span class="ot">&lt;-</span> pbmc <span class="sc">%&gt;%</span></span>
<span id="cb5-2"><a href="#cb5-2" tabindex="-1"></a>    <span class="fu">NormalizeData</span>(<span class="at">verbose =</span> <span class="cn">FALSE</span>)</span>
<span id="cb5-3"><a href="#cb5-3" tabindex="-1"></a></span>
<span id="cb5-4"><a href="#cb5-4" tabindex="-1"></a><span class="fu">VariableFeatures</span>(pbmc) <span class="ot">&lt;-</span> <span class="fu">split</span>(<span class="fu">row.names</span>(pbmc<span class="sc">@</span>meta.data), pbmc<span class="sc">@</span>meta.data<span class="sc">$</span>stim) <span class="sc">%&gt;%</span> <span class="fu">lapply</span>(<span class="cf">function</span>(cells_use) {</span>
<span id="cb5-5"><a href="#cb5-5" tabindex="-1"></a>    pbmc[,cells_use] <span class="sc">%&gt;%</span></span>
<span id="cb5-6"><a href="#cb5-6" tabindex="-1"></a>        <span class="fu">FindVariableFeatures</span>(<span class="at">selection.method =</span> <span class="st">&quot;vst&quot;</span>, <span class="at">nfeatures =</span> <span class="dv">2000</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb5-7"><a href="#cb5-7" tabindex="-1"></a>        <span class="fu">VariableFeatures</span>()</span>
<span id="cb5-8"><a href="#cb5-8" tabindex="-1"></a>}) <span class="sc">%&gt;%</span> unlist <span class="sc">%&gt;%</span> unique</span>
<span id="cb5-9"><a href="#cb5-9" tabindex="-1"></a><span class="co">#&gt; Finding variable features for layer counts</span></span>
<span id="cb5-10"><a href="#cb5-10" tabindex="-1"></a><span class="co">#&gt; Finding variable features for layer counts</span></span>
<span id="cb5-11"><a href="#cb5-11" tabindex="-1"></a></span>
<span id="cb5-12"><a href="#cb5-12" tabindex="-1"></a>pbmc <span class="ot">&lt;-</span> pbmc <span class="sc">%&gt;%</span> </span>
<span id="cb5-13"><a href="#cb5-13" tabindex="-1"></a>    <span class="fu">ScaleData</span>(<span class="at">verbose =</span> <span class="cn">FALSE</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb5-14"><a href="#cb5-14" tabindex="-1"></a>    <span class="fu">RunPCA</span>(<span class="at">features =</span> <span class="fu">VariableFeatures</span>(pbmc), <span class="at">npcs =</span> <span class="dv">20</span>, <span class="at">verbose =</span> <span class="cn">FALSE</span>)</span></code></pre></div>
</details>
</div>
<div id="perform-an-integrated-analysis" class="section level2">
<h2>Perform an integrated analysis</h2>
<p>To run harmony on Seurat object after it has been normalized, only
one argument needs to be specified which contains the batch covariate
located in the metadata. For this vignette, further parameters are
specified to align the dataset but the minimum parameters are shown in
the snippet below:</p>
<details class="chunk-details" open><summary class="chunk-summary"><span class="chunk-summary-text">Code</span></summary>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" tabindex="-1"></a><span class="do">## run harmony with default parameters</span></span>
<span id="cb6-2"><a href="#cb6-2" tabindex="-1"></a>pbmc <span class="ot">&lt;-</span> pbmc <span class="sc">%&gt;%</span> <span class="fu">RunHarmony</span>(<span class="st">&quot;stim&quot;</span>)</span>
<span id="cb6-3"><a href="#cb6-3" tabindex="-1"></a><span class="do">## is equivalent to:</span></span>
<span id="cb6-4"><a href="#cb6-4" tabindex="-1"></a>pbmc <span class="ot">&lt;-</span> <span class="fu">RunHarmony</span>(pbmc, <span class="st">&quot;stim&quot;</span>)</span></code></pre></div>
</details>
<p>Here, we will be running harmony with some indicative parameters and
plotting the convergence plot to illustrate some of the under the hood
functionality.</p>
<details class="chunk-details" open><summary class="chunk-summary"><span class="chunk-summary-text">Code</span></summary>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" tabindex="-1"></a></span>
<span id="cb7-2"><a href="#cb7-2" tabindex="-1"></a>pbmc <span class="ot">&lt;-</span> pbmc <span class="sc">%&gt;%</span> </span>
<span id="cb7-3"><a href="#cb7-3" tabindex="-1"></a>    <span class="fu">RunHarmony</span>(<span class="st">&quot;stim&quot;</span>, <span class="at">plot_convergence =</span> <span class="cn">TRUE</span>, <span class="at">nclust =</span> <span class="dv">50</span>, <span class="at">max_iter =</span> <span class="dv">10</span>, <span class="at">early_stop =</span> T)</span>
<span id="cb7-4"><a href="#cb7-4" tabindex="-1"></a><span class="co">#&gt; Transposing data matrix</span></span>
<span id="cb7-5"><a href="#cb7-5" tabindex="-1"></a><span class="co">#&gt; Initializing state using k-means centroids initialization</span></span>
<span id="cb7-6"><a href="#cb7-6" tabindex="-1"></a><span class="co">#&gt; Harmony 1/10</span></span>
<span id="cb7-7"><a href="#cb7-7" tabindex="-1"></a><span class="co">#&gt; Harmony 2/10</span></span>
<span id="cb7-8"><a href="#cb7-8" tabindex="-1"></a><span class="co">#&gt; Harmony 3/10</span></span>
<span id="cb7-9"><a href="#cb7-9" tabindex="-1"></a><span class="co">#&gt; Harmony 4/10</span></span>
<span id="cb7-10"><a href="#cb7-10" tabindex="-1"></a><span class="co">#&gt; Harmony 5/10</span></span>
<span id="cb7-11"><a href="#cb7-11" tabindex="-1"></a><span class="co">#&gt; Harmony converged after 5 iterations</span></span></code></pre></div>
</details>
<div class="figure" style="text-align: center">
<img src="" alt="By setting `plot_converge=TRUE`, harmony will generate a plot with its objective showing the flow of the integration. Each point represents the cost measured after a clustering round. Different colors represent different Harmony iterations which is controlled by `max_iter` (assuming that early_stop=FALSE). Here `max_iter=10` and up to 10 correction steps are expected. However, `early_stop=TRUE` so harmony will stop after the cost plateaus." width="50%" />
<p class="caption">
By setting <code>plot_converge=TRUE</code>, harmony will generate a plot
with its objective showing the flow of the integration. Each point
represents the cost measured after a clustering round. Different colors
represent different Harmony iterations which is controlled by
<code>max_iter</code> (assuming that early_stop=FALSE). Here
<code>max_iter=10</code> and up to 10 correction steps are expected.
However, <code>early_stop=TRUE</code> so harmony will stop after the
cost plateaus.
</p>
</div>
<div id="harmony-api-parameters-on-seurat-objects" class="section level3">
<h3>Harmony API parameters on Seurat objects</h3>
<p><code>RunHarmony</code> has several parameters accessible to users
which are outlined below.</p>
<div id="object-required" class="section level4">
<h4><code>object</code> (required)</h4>
<p>The Seurat object. This vignette assumes Seurat objects are version
5.</p>
</div>
<div id="group.by.vars-required" class="section level4">
<h4><code>group.by.vars</code> (required)</h4>
<p>A character vector that specifies all the experimental covariates to
be corrected/harmonized by the algorithm.</p>
<p>When using <code>RunHarmony()</code> with Seurat, harmony will look
up the <code>group.by.vars</code> metadata fields in the Seurat Object
metadata.</p>
<p>For example, given the <code>pbmc[[&quot;stim&quot;]]</code> exists as the stim
condition, setting <code>group.by.vars=&quot;stim&quot;</code> will perform
integration of these samples accordingly. If you want to integrate on
another variable, it needs to be present in Seurat object’s
meta.data.</p>
<p>To correct for several covariates, specify them in a vector:
<code>group.by.vars = c(&quot;stim&quot;, &quot;new_covariate&quot;)</code>.</p>
</div>
<div id="reduction.use" class="section level4">
<h4><code>reduction.use</code></h4>
<p>The cell embeddings to be used for the batch alignment. This
parameter assumes that a reduced dimension already exists in the
reduction slot of the Seurat object. By default, the <code>pca</code>
reduction is used.</p>
</div>
<div id="dims.use" class="section level4">
<h4><code>dims.use</code></h4>
<p>Optional parameter which can use a name vector to select specific
dimensions to be harmonized.</p>
</div>
</div>
<div id="algorithm-parameters" class="section level3">
<h3>Algorithm parameters</h3>
<div class="float">
<img src="" style="width:100.0%" alt="Harmony Algorithm Overview" />
<div class="figcaption">Harmony Algorithm Overview</div>
</div>
<div id="nclust" class="section level4">
<h4><code>nclust</code></h4>
<p>is a positive integer. Under the hood, harmony applies k-means
soft-clustering. For this task, <code>k</code> needs to be determined.
<code>nclust</code> corresponds to <code>k</code>. The harmonization
results and performance are not particularly sensitive for a reasonable
range of this parameter value. If this parameter is not set, harmony
will autodetermine this based on the dataset size with a maximum cap of
200. For dataset with a vast amount of different cell types and batches
this pamameter may need to be determined manually.</p>
</div>
<div id="sigma" class="section level4">
<h4><code>sigma</code></h4>
<p>a positive scalar that controls the soft clustering probability
assignment of single-cells to different clusters. Larger values will
assign a larger probability to distant clusters of cells resulting in a
different correction profile. Single-cells are assigned to clusters by
their euclidean distance <span class="math inline">\(d\)</span> to some
cluster center <span class="math inline">\(Y\)</span> after cosine
normalization which is defined in the range [0,4]. The clustering
probability of each cell is calculated as <span class="math inline">\(e^{-\frac{d}{\sigma}}\)</span> where <span class="math inline">\(\sigma\)</span> is controlled by the
<code>sigma</code> parameter. Default value of <code>sigma</code> is 0.1
and it generally works well since it defines probability assignment of a
cell in the range <span class="math inline">\([e^{-40}, e^0]\)</span>.
Larger values of <code>sigma</code> restrict the dynamic range of
probabilities that can be assigned to cells. For example,
<code>sigma=1</code> will yield a probabilities in the range of <span class="math inline">\([e^{-4}, e^0]\)</span>.</p>
</div>
<div id="theta" class="section level4">
<h4><code>theta</code></h4>
<p><code>theta</code> is a positive scalar vector that determines the
coefficient of harmony’s diversity penalty for each corrected
experimental covariate. In challenging experimental conditions,
increasing theta may result in better integration results. Theta is an
expontential parameter of the diversity penalty, thus setting
<code>theta=0</code> disables this penalty while increasing it to
greater values than 1 will perform more aggressive corrections in an
expontential manner. By default, it will set <code>theta=2</code> for
each experimental covariate.</p>
</div>
<div id="max_iter" class="section level4">
<h4><code>max_iter</code></h4>
<p>The number of correction steps harmony will perform before completing
the data set integration. In general, more iterations than necessary
increases computational runtime especially which becomes evident in
bigger datasets. Setting <code>early_stop=TRUE</code> may reduce the
actual number of correction steps which will be smaller than
<code>max_iter</code>.</p>
</div>
<div id="early_stop" class="section level4">
<h4><code>early_stop</code></h4>
<p>Under the hood, harmony minimizes its objective function through a
series of clustering and integration tests. By setting
<code>early_stop=TRUE</code>, when the objective function is less than
<code>1e-4</code> after a correction step harmony exits before reaching
the <code>max_iter</code> correction steps. This parameter can
drastically reduce run-time in bigger datasets.</p>
</div>
<div id="options" class="section level4">
<h4><code>.options</code></h4>
<p>A set of internal algorithm parameters that can be overriden. For
advanced users only.</p>
</div>
</div>
<div id="seurat-specific-parameters" class="section level3">
<h3>Seurat specific parameters</h3>
<p>These parameters are Seurat-specific and do not affect the flow of
the algorithm.</p>
<div id="project_dim" class="section level4">
<h4><code>project_dim</code></h4>
<p>Toggle-like parameter, by default <code>project_dim=TRUE</code>. When
enabled, <code>RunHarmony()</code> calculates genomic feature loadings
using Seurat’s <code>ProjectDim()</code> that correspond to the
harmonized cell embeddings.</p>
</div>
<div id="reduction.save" class="section level4">
<h4><code>reduction.save</code></h4>
<p>The new Reduced Dimension slot identifier. By default,
<code>reduction.save=TRUE</code>. This option allows several independent
runs of harmony to be retained in the appropriate slots in the
SeuratObjects. It is useful if you want to try Harmony with multiple
parameters and save them as e.g. ‘harmony_theta0’, ‘harmony_theta1’,
‘harmony_theta2’.</p>
</div>
</div>
<div id="miscellaneous-parameters" class="section level3">
<h3>Miscellaneous parameters</h3>
<p>These parameters help users troubleshoot harmony.</p>
<div id="plot_convergence" class="section level4">
<h4><code>plot_convergence</code></h4>
<p>Option that plots the convergence plot after the execution of the
algorithm. By default <code>FALSE</code>. Setting it to
<code>TRUE</code> will collect harmony’s objective value and plot it
allowing the user to troubleshoot the flow of the algorithm and
fine-tune the parameters of the dataset integration procedure.</p>
</div>
</div>
<div id="accessing-the-data" class="section level3">
<h3>Accessing the data</h3>
<p><code>RunHarmony()</code> returns the Seurat object which contains
the harmonized cell embeddings in a slot named <strong>harmony</strong>.
This entry can be accessed via <code>pbmc@reductions$harmony</code>. To
access the values of the cell embeddings we can also use:</p>
<details class="chunk-details" open><summary class="chunk-summary"><span class="chunk-summary-text">Code</span></summary>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" tabindex="-1"></a>harmony.embeddings <span class="ot">&lt;-</span> <span class="fu">Embeddings</span>(pbmc, <span class="at">reduction =</span> <span class="st">&quot;harmony&quot;</span>)</span></code></pre></div>
</details>
</div>
<div id="inspection-of-the-modalities" class="section level3">
<h3>Inspection of the modalities</h3>
<p>After Harmony integration, we should inspect the quality of the
harmonization and contrast it with the unharmonized algorithm input.
Ideally, cells from different conditions will align along the Harmonized
PCs. If they are not, you could increase the <em>theta</em> value above
to force a more aggressive fit of the dataset and rerun the
workflow.</p>
<details class="chunk-details" open><summary class="chunk-summary"><span class="chunk-summary-text">Code</span></summary>
<div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" tabindex="-1"></a></span>
<span id="cb9-2"><a href="#cb9-2" tabindex="-1"></a>p1 <span class="ot">&lt;-</span> <span class="fu">DimPlot</span>(<span class="at">object =</span> pbmc, <span class="at">reduction =</span> <span class="st">&quot;harmony&quot;</span>, <span class="at">pt.size =</span> .<span class="dv">1</span>, <span class="at">group.by =</span> <span class="st">&quot;stim&quot;</span>)</span>
<span id="cb9-3"><a href="#cb9-3" tabindex="-1"></a>p2 <span class="ot">&lt;-</span> <span class="fu">VlnPlot</span>(<span class="at">object =</span> pbmc, <span class="at">features =</span> <span class="st">&quot;harmony_1&quot;</span>, <span class="at">group.by =</span> <span class="st">&quot;stim&quot;</span>,  <span class="at">pt.size =</span> .<span class="dv">1</span>)</span>
<span id="cb9-4"><a href="#cb9-4" tabindex="-1"></a><span class="fu">plot_grid</span>(p1,p2)</span></code></pre></div>
</details>
<div class="figure" style="text-align: center">
<img src="" alt="Evaluate harmonization of stim parameter in the harmony generated cell embeddings" width="100%" />
<p class="caption">
Evaluate harmonization of stim parameter in the harmony generated cell
embeddings
</p>
</div>
<p>Plot Genes correlated with the Harmonized PCs</p>
<details class="chunk-details" open><summary class="chunk-summary"><span class="chunk-summary-text">Code</span></summary>
<div class="sourceCode" id="cb10"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" tabindex="-1"></a></span>
<span id="cb10-2"><a href="#cb10-2" tabindex="-1"></a><span class="fu">DimHeatmap</span>(<span class="at">object =</span> pbmc, <span class="at">reduction =</span> <span class="st">&quot;harmony&quot;</span>, <span class="at">cells =</span> <span class="dv">500</span>, <span class="at">dims =</span> <span class="dv">1</span><span class="sc">:</span><span class="dv">3</span>)</span></code></pre></div>
</details>
<p><img src="" width="100%" /></p>
</div>
</div>
</div>
<div id="using-harmony-embeddings-for-dimensionality-reduction-in-seurat" class="section level1">
<h1>Using harmony embeddings for dimensionality reduction in Seurat</h1>
<p>The harmonized cell embeddings generated by harmony can be used for
further integrated analyses. In this workflow, the Seurat object
contains the harmony <code>reduction</code> modality name in the method
that requires it.</p>
<div id="perform-clustering-using-the-harmonized-vectors-of-cells" class="section level2">
<h2>Perform clustering using the harmonized vectors of cells</h2>
<details class="chunk-details" open><summary class="chunk-summary"><span class="chunk-summary-text">Code</span></summary>
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" tabindex="-1"></a>pbmc <span class="ot">&lt;-</span> pbmc <span class="sc">%&gt;%</span></span>
<span id="cb11-2"><a href="#cb11-2" tabindex="-1"></a>    <span class="fu">FindNeighbors</span>(<span class="at">reduction =</span> <span class="st">&quot;harmony&quot;</span>) <span class="sc">%&gt;%</span></span>
<span id="cb11-3"><a href="#cb11-3" tabindex="-1"></a>    <span class="fu">FindClusters</span>(<span class="at">resolution =</span> <span class="fl">0.5</span>) </span>
<span id="cb11-4"><a href="#cb11-4" tabindex="-1"></a><span class="co">#&gt; Computing nearest neighbor graph</span></span>
<span id="cb11-5"><a href="#cb11-5" tabindex="-1"></a><span class="co">#&gt; Computing SNN</span></span>
<span id="cb11-6"><a href="#cb11-6" tabindex="-1"></a><span class="co">#&gt; Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck</span></span>
<span id="cb11-7"><a href="#cb11-7" tabindex="-1"></a><span class="co">#&gt; </span></span>
<span id="cb11-8"><a href="#cb11-8" tabindex="-1"></a><span class="co">#&gt; Number of nodes: 2000</span></span>
<span id="cb11-9"><a href="#cb11-9" tabindex="-1"></a><span class="co">#&gt; Number of edges: 71873</span></span>
<span id="cb11-10"><a href="#cb11-10" tabindex="-1"></a><span class="co">#&gt; </span></span>
<span id="cb11-11"><a href="#cb11-11" tabindex="-1"></a><span class="co">#&gt; Running Louvain algorithm...</span></span>
<span id="cb11-12"><a href="#cb11-12" tabindex="-1"></a><span class="co">#&gt; Maximum modularity in 10 random starts: 0.8714</span></span>
<span id="cb11-13"><a href="#cb11-13" tabindex="-1"></a><span class="co">#&gt; Number of communities: 10</span></span>
<span id="cb11-14"><a href="#cb11-14" tabindex="-1"></a><span class="co">#&gt; Elapsed time: 0 seconds</span></span></code></pre></div>
</details>
</div>
<div id="tsne-dimensionality-reduction" class="section level2">
<h2>TSNE dimensionality reduction</h2>
<details class="chunk-details" open><summary class="chunk-summary"><span class="chunk-summary-text">Code</span></summary>
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" tabindex="-1"></a>pbmc <span class="ot">&lt;-</span> pbmc <span class="sc">%&gt;%</span></span>
<span id="cb12-2"><a href="#cb12-2" tabindex="-1"></a>    <span class="fu">RunTSNE</span>(<span class="at">reduction =</span> <span class="st">&quot;harmony&quot;</span>)</span>
<span id="cb12-3"><a href="#cb12-3" tabindex="-1"></a></span>
<span id="cb12-4"><a href="#cb12-4" tabindex="-1"></a></span>
<span id="cb12-5"><a href="#cb12-5" tabindex="-1"></a>p1 <span class="ot">&lt;-</span> <span class="fu">DimPlot</span>(pbmc, <span class="at">reduction =</span> <span class="st">&quot;tsne&quot;</span>, <span class="at">group.by =</span> <span class="st">&quot;stim&quot;</span>, <span class="at">pt.size =</span> .<span class="dv">1</span>)</span>
<span id="cb12-6"><a href="#cb12-6" tabindex="-1"></a>p2 <span class="ot">&lt;-</span> <span class="fu">DimPlot</span>(pbmc, <span class="at">reduction =</span> <span class="st">&quot;tsne&quot;</span>, <span class="at">label =</span> <span class="cn">TRUE</span>, <span class="at">pt.size =</span> .<span class="dv">1</span>)</span>
<span id="cb12-7"><a href="#cb12-7" tabindex="-1"></a><span class="fu">plot_grid</span>(p1, p2)</span></code></pre></div>
</details>
<div class="figure" style="text-align: center">
<img src="" alt="t-SNE Visualization of harmony embeddings" />
<p class="caption">
t-SNE Visualization of harmony embeddings
</p>
</div>
<p>One important observation is to assess that the harmonized data
contain biological states of the cells. Therefore by checking the
following genes we can see that biological cell states are preserved
after harmonization.</p>
<details class="chunk-details" open><summary class="chunk-summary"><span class="chunk-summary-text">Code</span></summary>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" tabindex="-1"></a><span class="fu">FeaturePlot</span>(<span class="at">object =</span> pbmc, <span class="at">features=</span> <span class="fu">c</span>(<span class="st">&quot;CD3D&quot;</span>, <span class="st">&quot;SELL&quot;</span>, <span class="st">&quot;CREM&quot;</span>, <span class="st">&quot;CD8A&quot;</span>, <span class="st">&quot;GNLY&quot;</span>, <span class="st">&quot;CD79A&quot;</span>, <span class="st">&quot;FCGR3A&quot;</span>, <span class="st">&quot;CCL2&quot;</span>, <span class="st">&quot;PPBP&quot;</span>), </span>
<span id="cb13-2"><a href="#cb13-2" tabindex="-1"></a>            <span class="at">min.cutoff =</span> <span class="st">&quot;q9&quot;</span>, <span class="at">cols =</span> <span class="fu">c</span>(<span class="st">&quot;lightgrey&quot;</span>, <span class="st">&quot;blue&quot;</span>), <span class="at">pt.size =</span> <span class="fl">0.5</span>)</span></code></pre></div>
</details>
<div class="figure">
<img src="" alt="Expression of gene panel heatmap in the harmonized PBMC dataset" width="100%" />
<p class="caption">
Expression of gene panel heatmap in the harmonized PBMC dataset
</p>
</div>
</div>
<div id="umap" class="section level2">
<h2>UMAP</h2>
<p>Very similarly with TSNE we can run UMAP by passing the harmony
reduction in the function.</p>
<details class="chunk-details" open><summary class="chunk-summary"><span class="chunk-summary-text">Code</span></summary>
<div class="sourceCode" id="cb14"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" tabindex="-1"></a>pbmc <span class="ot">&lt;-</span> pbmc <span class="sc">%&gt;%</span></span>
<span id="cb14-2"><a href="#cb14-2" tabindex="-1"></a>    <span class="fu">RunUMAP</span>(<span class="at">reduction =</span> <span class="st">&quot;harmony&quot;</span>,  <span class="at">dims =</span> <span class="dv">1</span><span class="sc">:</span><span class="dv">20</span>)</span>
<span id="cb14-3"><a href="#cb14-3" tabindex="-1"></a><span class="co">#&gt; Warning: The default method for RunUMAP has changed from calling Python UMAP via reticulate to the R-native UWOT using the cosine metric</span></span>
<span id="cb14-4"><a href="#cb14-4" tabindex="-1"></a><span class="co">#&gt; To use Python UMAP via reticulate, set umap.method to &#39;umap-learn&#39; and metric to &#39;correlation&#39;</span></span>
<span id="cb14-5"><a href="#cb14-5" tabindex="-1"></a><span class="co">#&gt; This message will be shown once per session</span></span>
<span id="cb14-6"><a href="#cb14-6" tabindex="-1"></a><span class="co">#&gt; 15:15:55 UMAP embedding parameters a = 0.9922 b = 1.112</span></span>
<span id="cb14-7"><a href="#cb14-7" tabindex="-1"></a><span class="co">#&gt; 15:15:55 Read 2000 rows and found 20 numeric columns</span></span>
<span id="cb14-8"><a href="#cb14-8" tabindex="-1"></a><span class="co">#&gt; 15:15:55 Using Annoy for neighbor search, n_neighbors = 30</span></span>
<span id="cb14-9"><a href="#cb14-9" tabindex="-1"></a><span class="co">#&gt; 15:15:55 Building Annoy index with metric = cosine, n_trees = 50</span></span>
<span id="cb14-10"><a href="#cb14-10" tabindex="-1"></a><span class="co">#&gt; 0%   10   20   30   40   50   60   70   80   90   100%</span></span>
<span id="cb14-11"><a href="#cb14-11" tabindex="-1"></a><span class="co">#&gt; [----|----|----|----|----|----|----|----|----|----|</span></span>
<span id="cb14-12"><a href="#cb14-12" tabindex="-1"></a><span class="co">#&gt; **************************************************|</span></span>
<span id="cb14-13"><a href="#cb14-13" tabindex="-1"></a><span class="co">#&gt; 15:15:55 Writing NN index file to temp file /tmp/RtmpzXP8UJ/file82d94bfc74c7</span></span>
<span id="cb14-14"><a href="#cb14-14" tabindex="-1"></a><span class="co">#&gt; 15:15:55 Searching Annoy index using 1 thread, search_k = 3000</span></span>
<span id="cb14-15"><a href="#cb14-15" tabindex="-1"></a><span class="co">#&gt; 15:15:56 Annoy recall = 100%</span></span>
<span id="cb14-16"><a href="#cb14-16" tabindex="-1"></a><span class="co">#&gt; 15:15:56 Commencing smooth kNN distance calibration using 1 thread with target n_neighbors = 30</span></span>
<span id="cb14-17"><a href="#cb14-17" tabindex="-1"></a><span class="co">#&gt; 15:15:56 Initializing from normalized Laplacian + noise (using RSpectra)</span></span>
<span id="cb14-18"><a href="#cb14-18" tabindex="-1"></a><span class="co">#&gt; 15:15:56 Commencing optimization for 500 epochs, with 83170 positive edges</span></span>
<span id="cb14-19"><a href="#cb14-19" tabindex="-1"></a><span class="co">#&gt; 15:15:58 Optimization finished</span></span>
<span id="cb14-20"><a href="#cb14-20" tabindex="-1"></a></span>
<span id="cb14-21"><a href="#cb14-21" tabindex="-1"></a>p1 <span class="ot">&lt;-</span> <span class="fu">DimPlot</span>(pbmc, <span class="at">reduction =</span> <span class="st">&quot;umap&quot;</span>, <span class="at">group.by =</span> <span class="st">&quot;stim&quot;</span>, <span class="at">pt.size =</span> .<span class="dv">1</span>)</span>
<span id="cb14-22"><a href="#cb14-22" tabindex="-1"></a>p2 <span class="ot">&lt;-</span> <span class="fu">DimPlot</span>(pbmc, <span class="at">reduction =</span> <span class="st">&quot;umap&quot;</span>, <span class="at">label =</span> <span class="cn">TRUE</span>,  <span class="at">pt.size =</span> .<span class="dv">1</span>)</span>
<span id="cb14-23"><a href="#cb14-23" tabindex="-1"></a><span class="fu">plot_grid</span>(p1, p2)</span></code></pre></div>
</details>
<div class="figure" style="text-align: center">
<img src="" alt="UMAP Visualization of harmony embeddings" />
<p class="caption">
UMAP Visualization of harmony embeddings
</p>
</div>
<details class="chunk-details" open><summary class="chunk-summary"><span class="chunk-summary-text">Code</span></summary>
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" tabindex="-1"></a><span class="fu">sessionInfo</span>()</span>
<span id="cb15-2"><a href="#cb15-2" tabindex="-1"></a><span class="co">#&gt; R version 4.2.0 (2022-04-22)</span></span>
<span id="cb15-3"><a href="#cb15-3" tabindex="-1"></a><span class="co">#&gt; Platform: x86_64-conda-linux-gnu (64-bit)</span></span>
<span id="cb15-4"><a href="#cb15-4" tabindex="-1"></a><span class="co">#&gt; Running under: Arch Linux</span></span>
<span id="cb15-5"><a href="#cb15-5" tabindex="-1"></a><span class="co">#&gt; </span></span>
<span id="cb15-6"><a href="#cb15-6" tabindex="-1"></a><span class="co">#&gt; Matrix products: default</span></span>
<span id="cb15-7"><a href="#cb15-7" tabindex="-1"></a><span class="co">#&gt; BLAS/LAPACK: /home/main/miniconda3/envs/Renv/lib/libopenblasp-r0.3.21.so</span></span>
<span id="cb15-8"><a href="#cb15-8" tabindex="-1"></a><span class="co">#&gt; </span></span>
<span id="cb15-9"><a href="#cb15-9" tabindex="-1"></a><span class="co">#&gt; locale:</span></span>
<span id="cb15-10"><a href="#cb15-10" tabindex="-1"></a><span class="co">#&gt;  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              </span></span>
<span id="cb15-11"><a href="#cb15-11" tabindex="-1"></a><span class="co">#&gt;  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    </span></span>
<span id="cb15-12"><a href="#cb15-12" tabindex="-1"></a><span class="co">#&gt;  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   </span></span>
<span id="cb15-13"><a href="#cb15-13" tabindex="-1"></a><span class="co">#&gt;  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 </span></span>
<span id="cb15-14"><a href="#cb15-14" tabindex="-1"></a><span class="co">#&gt;  [9] LC_ADDRESS=C               LC_TELEPHONE=C            </span></span>
<span id="cb15-15"><a href="#cb15-15" tabindex="-1"></a><span class="co">#&gt; [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       </span></span>
<span id="cb15-16"><a href="#cb15-16" tabindex="-1"></a><span class="co">#&gt; </span></span>
<span id="cb15-17"><a href="#cb15-17" tabindex="-1"></a><span class="co">#&gt; attached base packages:</span></span>
<span id="cb15-18"><a href="#cb15-18" tabindex="-1"></a><span class="co">#&gt; [1] stats     graphics  grDevices utils     datasets  methods   base     </span></span>
<span id="cb15-19"><a href="#cb15-19" tabindex="-1"></a><span class="co">#&gt; </span></span>
<span id="cb15-20"><a href="#cb15-20" tabindex="-1"></a><span class="co">#&gt; other attached packages:</span></span>
<span id="cb15-21"><a href="#cb15-21" tabindex="-1"></a><span class="co">#&gt;  [1] cowplot_1.1.3      Seurat_5.0.1       SeuratObject_5.0.1 sp_1.6-1          </span></span>
<span id="cb15-22"><a href="#cb15-22" tabindex="-1"></a><span class="co">#&gt;  [5] patchwork_1.2.0    harmony_1.2.1      Rcpp_1.0.12        ggrepel_0.9.3     </span></span>
<span id="cb15-23"><a href="#cb15-23" tabindex="-1"></a><span class="co">#&gt;  [9] ggthemes_4.2.4     lubridate_1.9.2    forcats_1.0.0      stringr_1.5.0     </span></span>
<span id="cb15-24"><a href="#cb15-24" tabindex="-1"></a><span class="co">#&gt; [13] dplyr_1.1.4        purrr_1.0.2        readr_2.1.4        tidyr_1.3.0       </span></span>
<span id="cb15-25"><a href="#cb15-25" tabindex="-1"></a><span class="co">#&gt; [17] tibble_3.2.1       ggplot2_3.5.1      tidyverse_2.0.0    data.table_1.14.8 </span></span>
<span id="cb15-26"><a href="#cb15-26" tabindex="-1"></a><span class="co">#&gt; </span></span>
<span id="cb15-27"><a href="#cb15-27" tabindex="-1"></a><span class="co">#&gt; loaded via a namespace (and not attached):</span></span>
<span id="cb15-28"><a href="#cb15-28" tabindex="-1"></a><span class="co">#&gt;   [1] Rtsne_0.16             colorspace_2.1-0       deldir_1.0-9          </span></span>
<span id="cb15-29"><a href="#cb15-29" tabindex="-1"></a><span class="co">#&gt;   [4] ellipsis_0.3.2         ggridges_0.5.4         RcppHNSW_0.6.0        </span></span>
<span id="cb15-30"><a href="#cb15-30" tabindex="-1"></a><span class="co">#&gt;   [7] spatstat.data_3.0-1    leiden_0.4.3           listenv_0.9.0         </span></span>
<span id="cb15-31"><a href="#cb15-31" tabindex="-1"></a><span class="co">#&gt;  [10] farver_2.1.2           RSpectra_0.16-1        fansi_1.0.6           </span></span>
<span id="cb15-32"><a href="#cb15-32" tabindex="-1"></a><span class="co">#&gt;  [13] codetools_0.2-19       splines_4.2.0          cachem_1.0.7          </span></span>
<span id="cb15-33"><a href="#cb15-33" tabindex="-1"></a><span class="co">#&gt;  [16] knitr_1.42             polyclip_1.10-4        spam_2.10-0           </span></span>
<span id="cb15-34"><a href="#cb15-34" tabindex="-1"></a><span class="co">#&gt;  [19] jsonlite_1.8.7         RhpcBLASctl_0.23-42    ica_1.0-3             </span></span>
<span id="cb15-35"><a href="#cb15-35" tabindex="-1"></a><span class="co">#&gt;  [22] cluster_2.1.4          png_0.1-8              uwot_0.1.16           </span></span>
<span id="cb15-36"><a href="#cb15-36" tabindex="-1"></a><span class="co">#&gt;  [25] spatstat.sparse_3.0-1  sctransform_0.4.1      shiny_1.7.4           </span></span>
<span id="cb15-37"><a href="#cb15-37" tabindex="-1"></a><span class="co">#&gt;  [28] compiler_4.2.0         httr_1.4.5             Matrix_1.6-3          </span></span>
<span id="cb15-38"><a href="#cb15-38" tabindex="-1"></a><span class="co">#&gt;  [31] fastmap_1.1.1          lazyeval_0.2.2         cli_3.6.2             </span></span>
<span id="cb15-39"><a href="#cb15-39" tabindex="-1"></a><span class="co">#&gt;  [34] later_1.3.0            htmltools_0.5.6.1      tools_4.2.0           </span></span>
<span id="cb15-40"><a href="#cb15-40" tabindex="-1"></a><span class="co">#&gt;  [37] igraph_1.6.0           dotCall64_1.1-1        gtable_0.3.5          </span></span>
<span id="cb15-41"><a href="#cb15-41" tabindex="-1"></a><span class="co">#&gt;  [40] glue_1.7.0             reshape2_1.4.4         RANN_2.6.1            </span></span>
<span id="cb15-42"><a href="#cb15-42" tabindex="-1"></a><span class="co">#&gt;  [43] scattermore_1.2        jquerylib_0.1.4        vctrs_0.6.5           </span></span>
<span id="cb15-43"><a href="#cb15-43" tabindex="-1"></a><span class="co">#&gt;  [46] nlme_3.1-162           spatstat.explore_3.2-1 progressr_0.13.0      </span></span>
<span id="cb15-44"><a href="#cb15-44" tabindex="-1"></a><span class="co">#&gt;  [49] lmtest_0.9-40          spatstat.random_3.1-5  xfun_0.40             </span></span>
<span id="cb15-45"><a href="#cb15-45" tabindex="-1"></a><span class="co">#&gt;  [52] globals_0.16.2         timechange_0.2.0       mime_0.12             </span></span>
<span id="cb15-46"><a href="#cb15-46" tabindex="-1"></a><span class="co">#&gt;  [55] miniUI_0.1.1.1         lifecycle_1.0.4        irlba_2.3.5.1         </span></span>
<span id="cb15-47"><a href="#cb15-47" tabindex="-1"></a><span class="co">#&gt;  [58] goftest_1.2-3          future_1.32.0          MASS_7.3-58.3         </span></span>
<span id="cb15-48"><a href="#cb15-48" tabindex="-1"></a><span class="co">#&gt;  [61] zoo_1.8-12             scales_1.3.0           spatstat.utils_3.0-5  </span></span>
<span id="cb15-49"><a href="#cb15-49" tabindex="-1"></a><span class="co">#&gt;  [64] hms_1.1.3              promises_1.2.0.1       parallel_4.2.0        </span></span>
<span id="cb15-50"><a href="#cb15-50" tabindex="-1"></a><span class="co">#&gt;  [67] RColorBrewer_1.1-3     yaml_2.3.7             gridExtra_2.3         </span></span>
<span id="cb15-51"><a href="#cb15-51" tabindex="-1"></a><span class="co">#&gt;  [70] reticulate_1.29        pbapply_1.7-0          sass_0.4.5            </span></span>
<span id="cb15-52"><a href="#cb15-52" tabindex="-1"></a><span class="co">#&gt;  [73] stringi_1.7.12         highr_0.10             fastDummies_1.7.3     </span></span>
<span id="cb15-53"><a href="#cb15-53" tabindex="-1"></a><span class="co">#&gt;  [76] rlang_1.1.3            pkgconfig_2.0.3        matrixStats_1.0.0     </span></span>
<span id="cb15-54"><a href="#cb15-54" tabindex="-1"></a><span class="co">#&gt;  [79] evaluate_0.22          lattice_0.20-45        tensor_1.5            </span></span>
<span id="cb15-55"><a href="#cb15-55" tabindex="-1"></a><span class="co">#&gt;  [82] ROCR_1.0-11            htmlwidgets_1.6.2      labeling_0.4.3        </span></span>
<span id="cb15-56"><a href="#cb15-56" tabindex="-1"></a><span class="co">#&gt;  [85] tidyselect_1.2.1       parallelly_1.36.0      RcppAnnoy_0.0.22      </span></span>
<span id="cb15-57"><a href="#cb15-57" tabindex="-1"></a><span class="co">#&gt;  [88] plyr_1.8.8             magrittr_2.0.3         R6_2.5.1              </span></span>
<span id="cb15-58"><a href="#cb15-58" tabindex="-1"></a><span class="co">#&gt;  [91] generics_0.1.3         pillar_1.9.0           withr_3.0.0           </span></span>
<span id="cb15-59"><a href="#cb15-59" tabindex="-1"></a><span class="co">#&gt;  [94] fitdistrplus_1.1-11    abind_1.4-5            survival_3.5-5        </span></span>
<span id="cb15-60"><a href="#cb15-60" tabindex="-1"></a><span class="co">#&gt;  [97] future.apply_1.11.0    KernSmooth_2.23-21     utf8_1.2.4            </span></span>
<span id="cb15-61"><a href="#cb15-61" tabindex="-1"></a><span class="co">#&gt; [100] spatstat.geom_3.2-1    plotly_4.10.2          tzdb_0.4.0            </span></span>
<span id="cb15-62"><a href="#cb15-62" tabindex="-1"></a><span class="co">#&gt; [103] rmarkdown_2.21         grid_4.2.0             digest_0.6.33         </span></span>
<span id="cb15-63"><a href="#cb15-63" tabindex="-1"></a><span class="co">#&gt; [106] xtable_1.8-4           httpuv_1.6.9           munsell_0.5.1         </span></span>
<span id="cb15-64"><a href="#cb15-64" tabindex="-1"></a><span class="co">#&gt; [109] viridisLite_0.4.2      bslib_0.4.2</span></span></code></pre></div>
</details>
</div>
</div>



<!-- code folding -->


<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src  = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>

</body>
</html>
